package edu.szu.huhanpeng.doodlingFight.controller 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.AsyncCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class DelayCmd extends AsyncCommand implements ICommand, INotifier 
	{
		private static const CHANGE_FAIL:int = 500;
		private static const MANAGE_DONE:int = 500;
		
		override public function execute(note:INotification):void 
		{
			var delay:int;
			switch (note.getName()) 
			{
				case GlobalConst.noteName.CHANGE_FAIL:
					delay = CHANGE_FAIL;
				break;
				
				case GlobalConst.noteName.MANAGE_DONE:
					delay = MANAGE_DONE;
				break;
				default:
			}
			
			if (delay != 0) 
			{
				var timer:Timer = new Timer( delay, 1 );
				timer.addEventListener(TimerEvent.TIMER, onTick);
				timer.start();
			}
			else
			{
				commandComplete();
			}
		}
		
		private function onTick(e:TimerEvent):void 
		{
			(e.currentTarget as Timer).removeEventListener(TimerEvent.TIMER, onTick);
			commandComplete();
		}
		
	}

}